<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{$title|default="默认标题"}</title>
    {load href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css" /}
    {load href="https://cdn.bootcss.com/jquery/2.2.1/jquery.min.js" /}
    {load href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/js/bootstrap.min.js" /}
</head>
<body>

<!-- 警告框 -->
<div class="alert fade" style="display: none; z-index: 2; position: fixed; top: 200px; left: 50%; width: 500px; margin-left: -200px">
    <div class="alertMsg text-center"></div>
</div>

<div class="container">
    <div class="row">
        <div class="col-md-4"></div>
        <div class="col-md-4">
            <div class="page-header text-center text-primary">
                <h3>管理员登录</h3>
            </div>
            <!-- 手机登录 -->
            <form class="form-horizontal" id="login_form">
                <div class="form-group">
                    <label class="col-sm-3 control-label">电话:</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" name="mobile" placeholder="Mobile" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">密码:</label>
                    <div class="col-sm-9">
                        <input type="password" class="form-control" name="password" placeholder="Password">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-3 col-sm-9">
                        <button type="button" id="submitBtn" class="btn btn-primary btn-block">登录</button>
                    </div>
                </div>
            </form>
        </div>
        <div class="col-md-4"></div>
    </div>
</div>
<script type="text/javascript">
    // 封装警告框方法
    function showAlert(alertStyle, alertText, alertTime) {
        $('.alert').css('display', 'block');
        $('.alert').addClass(alertStyle);
        $('.alertMsg').text(alertText);
        $('.alert').removeClass('fade').addClass('in');

        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                $('.alert').addClass('fade').removeClass('in');
                $('.alert').css('display', 'none');
                resolve();
            }, alertTime)
        })
    }
    $(function () {
        $('#submitBtn').on('click', function () {
            $.ajax({
                type: 'post',
                url: "{:url('user/checkAdminLogin')}",
                contentType: 'json',
                data: $('#login_form').serialize(),
                success: function (data) {
                    switch (data.status) {
                        case 1:
                            window.location.href="{:url('index/index')}";
                            break;
                        case 0:
                        case -1:
                            showAlert('alert-danger', data.msg, 1000)
                            break;
                        default:
                            showAlert('alert-danger', data.msg, 1000)
                            break;
                    }
                }
            })
        })
    })
</script>

</body>
</html>